#include "TranslatingObject.h"
#include "include.h"

TranslatingObject::TranslatingObject(TextureManager * textureManager, Vertex position)
:ClosedObject(textureManager, position)
{
	VertexList * pathVertices = new VertexList();
	pathVertices->Add(&(this->position));
	pathVertices->Add(new Vertex(position.GetPosition() + Vector2D(5,0)));
	path = new Object(textureManager, pathVertices);
}
TranslatingObject::TranslatingObject(TextureManager * textureManager, Vertex position, VertexList * vertices)
:ClosedObject(textureManager, position, vertices)
{
	VertexList * pathVertices = new VertexList();
	pathVertices->Add(&(this->position));
	pathVertices->Add(new Vertex(position.GetPosition() + Vector2D(5,0)));
	path = new Object(textureManager, pathVertices);
}
TranslatingObject::TranslatingObject(TextureManager * textureManager, float textureRotation, VertexList * vertices, Material * material, Vector2D pos, VertexList * path, float mass, float speed)
:ClosedObject(textureManager, textureRotation, Vertex(pos), vertices, material, mass)
{
	printf("Translating Object constructor\n");
	if(path)
	{
		path->Add(&position);
		this->path = new Object(textureManager, path);
	}
	float speedCheck = speed;
	int size = 0;
	while(speedCheck > 1)
	{
		size++;
		speedCheck /= 10;
	}
	size += 6;
	char * speedString = (char*)malloc(sizeof(char)*size);
	sprintf(speedString, "%.3f", speed);
	CreatePropertyMenu();
	propertyMenu->SetFormContent(1,speedString);
	propertyMenu->Hide();
}
TranslatingObject::~TranslatingObject()
{
}
char * TranslatingObject::GetTag()
{
	printf("Getting border tag\n");
	char * points = vertices->GetRelativeTag(position.GetPosition());
	char * materialName = material->name;
	char * pathTag = path->GetVertices()->GetBackwardsTag();
	char * mass = propertyMenu->GetFormContent(0);
	char * speed = propertyMenu->GetFormContent(1);
	char * tag = (char *)malloc(strlen(points)+strlen(materialName)+strlen(pathTag)+strlen(mass)+strlen(speed)+50);
	int numPath = path->GetVertices()->GetLength();
	sprintf(tag, "<object,translatingobject,%s,%.3f,%d,%s,%s,%s,%d,%s>", materialName,textureRotation,vertices->GetLength(),points, speed,mass,numPath, pathTag);
	delete points;
	free(mass);
	free(speed);
	return tag;	
}
void TranslatingObject::CreatePropertyMenu()
{
	printf("TranslatingObject::CreatePropertyMenu\n");
	if(propertyMenu)
	{
		delete(propertyMenu);
		propertyMenu = NULL;
	}
	propertyMenu = new FormMenu(textureManager, "2,Speed,1,Mass,1", PROPERTY_MENU_POSITION, 0);
	float massCheck = mass;
	int size = 0;
	while(massCheck > 1)
	{
		size++;
		massCheck /= 10;
	}
	size += 6;
	char * massString = (char*)malloc(sizeof(char)*size);
	sprintf(massString, "%.3f", mass);
	propertyMenu->SetFormContent(0,massString);
}
Object * TranslatingObject::GetPath()
{
	return path;
}
